package com.peanut.interceptor;

import com.mvc.ResponseUtil;
import com.mvc.interceptor.HandlerInterceptor;
import com.peanut.constants.Constants;
import com.peanut.constants.Status;
import com.peanut.entity.JsonResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession(false);
		if(session != null){
			Object flag = session.getAttribute(Constants.LOGIN_USER);
			if(flag != null){
				return true;
			}
		}
		ResponseUtil.ServerError2(response, JsonResult.status(Status.NOT_LOGIN));
		return false;
	}
}
